package com.golddaymicromall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.golddaymicromall.activity.R;
import com.golddaymicromall.bean.RemittanceRegisterInfo;
import com.golddaymicromall.util.DateFormatUtils;

import java.util.List;

/**
 * Created by 王立强 on 2016/3/7 0007.
 */
public class RemittanceRegisterAdapter extends BaseAdapter {
    private List<RemittanceRegisterInfo> list;
    private Context ctx;
    LayoutInflater layoutinflater;
    DateFormatUtils dateFormatUtils;

    public RemittanceRegisterAdapter(List<RemittanceRegisterInfo> list, Context ctx) {
        this.list = list;
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder hold;
        View view = convertView;
        if (view == null) {
            hold = new ViewHolder();
            layoutinflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutinflater.inflate(R.layout.item_onlinepayment, null);
            hold.mRemitReg_Status = (TextView) view.findViewById(R.id.remitReg_status);
            hold.mRemitReg_Date = (TextView) view.findViewById(R.id.remitReg_date);
            hold.mRemitReg_RemitMoney = (TextView) view.findViewById(R.id.remitReg_remitMoney);
            hold.mRemitReg_ConfirmMoney = (TextView) view.findViewById(R.id.remitReg_confirmMoney);
            hold.mRemitReg_Confirmer = (TextView) view.findViewById(R.id.remitReg_confirmer);
            view.setTag(hold);
        } else {
            hold = (ViewHolder) view.getTag();
        }
        if (list.size() != 0) {
            hold.mRemitReg_Status.setText("(" + (list.get(position).getRstate().equals("0") ? "未审核" : "已审核")+")");
            hold.mRemitReg_Date.setText(dateFormatUtils.dateFormat(list.get(position).getRemittancedate().toString()));
            hold.mRemitReg_RemitMoney.setText(list.get(position).getRemittancemoney().toString().equals("null") ? "0.0" : list.get(position).getRemittancemoney().toString());
            hold.mRemitReg_ConfirmMoney.setText((list.get(position).getRmbmoney() + "").equals("null") ? "0.0" : (list.get(position).getRmbmoney() + ""));
            hold.mRemitReg_Confirmer.setText(list.get(position).getRemittanceuser());
        } else {
            hold.mRemitReg_Status.setText("您还有数据");
            hold.mRemitReg_Date.setVisibility(View.GONE);
            hold.mRemitReg_RemitMoney.setVisibility(View.GONE);
            hold.mRemitReg_ConfirmMoney.setVisibility(View.GONE);
            hold.mRemitReg_Confirmer.setVisibility(View.GONE);
        }

        return view;
    }

    private class ViewHolder {
        TextView mRemitReg_StoreNo;
        TextView mRemitReg_StoreName;
        TextView mRemitReg_Status;
        TextView mRemitReg_Date;
        TextView mRemitReg_RemitMoney;
        TextView mRemitReg_ConfirmMoney;
        TextView mRemitReg_Confirmer;
    }
}
